package cn.pzhu.controller.admin;

import cn.pzhu.controller.BaseController;
import cn.pzhu.model.User;
import cn.pzhu.services.admin.UserServices;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by dongp on 2016/4/23.
 */
public class UserController extends BaseController {

    private UserServices userServices = new UserServices();

    public void index() {
        render("user.jsp");
    }

    public void ajaxAdd() {
        String userID = getPara("userID");
        String userName = getPara("userName");
        String account = getPara("account");
        String password = getPara("password");
        Integer errorCount = getParaToInt("errorCount",0);
        Integer maxCount = getParaToInt("maxCount",10);
        Integer roleValue = getParaToInt("roleValue");

        boolean result = userServices.ajaxAdd(userID,userName,account,password,errorCount,maxCount,roleValue);
        render("user.jsp");
    }

    public void ajaxQuery() {
        String pageNumber = getPara("pageNumber");
        String pageSize = getPara("pageSize");
        String search = getPara("search","");
        List attrs = userServices.ajaxQuery(pageNumber,pageSize,search);
        renderJson(attrs);
    }

    public void ajaxUpdate() {
        String userID = getPara("userID");
        String userName = getPara("userName");
        String account = getPara("account");
        String password = getPara("password");
        Integer errorCount = getParaToInt("errorCount",0);
        Integer maxCount = getParaToInt("maxCount",10);
        Integer roleValue = getParaToInt("roleValue");

        boolean result = userServices.ajaxUpdate(userID,userName,account,password,errorCount,maxCount,roleValue);
        if(result) {
            setAttr("msg","success");// 该返回的成功信息前台暂时没用
        }else {
            setAttr("msg","failue");
        }

        render("user.jsp");
    }

    public void ajaxDel() {
        String userID = getPara("userID");
        boolean result = userServices.ajaxDel(userID);

        render("user.jsp");
    }
}
